#include "RuleManager.h"
#include "Config.h"

using namespace std;
using namespace ruleconfiguration;
using namespace npexception;

static const char g_ruleDir[] = "rule/";

RuleManager::RuleManager()
{
  string ruleFlag = Config::getInstance()->getConfig()->ruleflag;
  //string secondRules = Config::getInstance()->getHostConfig()->secondRules;

  m_rules[ruleFlag] = new Rule(string(g_ruleDir) + ruleFlag + ".xml");

  //备用规则文件 todo
}

RuleManager* RuleManager::getInstance() throw (int)
{
  static RuleManager* singleton = new RuleManager();
  return singleton;
}

RegexInfo* RuleManager::getRuleInfo(const std::string &flag, const std::string &regexName)
{
  Rule* rule = getRule(flag);
  return rule->getRegex(regexName);
}

Rule* RuleManager::getRule(const std::string &flag)
{
  static RulesMapIterator it;
  it = m_rules.find(flag);
  throwExIf(it == m_rules.end(), INVALID_RULE_FILE_NAME);
  return it->second;
}
